<template>
  <el-drawer
    :visible.sync="visible"
    title="工单回复"
    size="40%"
    :with-header="true"
    custom-class="workorder-reply-drawer"
    @close="handleClose"
  >
    <div class="drawer-content">
      <div class="drawer-row">
        <span class="drawer-label">工单主题：</span>
        <span class="drawer-value">{{ subject }}</span>
      </div>
      <div class="drawer-row">
        <span class="drawer-label">工单内容：</span>
        <span class="drawer-value">{{ content }}</span>
      </div>
      <div class="drawer-row align-top">
        <span class="drawer-label">工单回复：</span>
        <el-input
          type="textarea"
          v-model="reply"
          :rows="8"
          placeholder="请输入工单回复内容"
          class="reply-textarea"
        />
      </div>
      <div class="drawer-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSubmit">提交</el-button>
      </div>
    </div>
  </el-drawer>
</template>

<script>
export default {
  name: "WorkOrderReplyDrawer",
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    subject: {
      type: String,
      default: "",
    },
    content: {
      type: String,
      default: "",
    },
    value: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      reply: this.value,
    };
  },
  watch: {
    value(val) {
      this.reply = val;
    },
  },
  methods: {
    handleClose() {
      this.$emit("update:visible", false);
      this.$emit("cancel");
    },
    handleSubmit() {
      this.$emit("submit", this.reply);
    },
  },
};
</script>

<style scoped>
.workorder-reply-drawer .drawer-content {
  padding: 24px 16px 0 16px;
}
.drawer-row {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
}
.drawer-row.align-top {
  align-items: flex-start;
}
.drawer-label {
  width: 80px;
  font-weight: bold;
  color: #222;
  flex-shrink: 0;
}
.drawer-value {
  color: #444;
  flex: 1;
  word-break: break-all;
}
.reply-textarea {
  width: 100%;
}
.drawer-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 32px;
  gap: 16px;
}
</style>
